#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, x;
int a[N];
long long ans;

main() {
	cin >> n >> x;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
		if (a[i] + a[i + 1] > x) {
			ans += a[i + 1] - x + a[i];
			a[i + 1] = x - a[i];
		}
	cout << ans;
	return 0;
}